package com.pfsbuilder.Dialogs;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class Table_CellRenderer extends DefaultTableCellRenderer {
	Image errorImage = new ImageIcon(getClass().getClassLoader().getResource("com/pfsbuilder/images/PTable_CellRenderer/error.png")).getImage();

	String value;

	public Table_CellRenderer() {
	}

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		this.value = (String) value;
		return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	}

	public void paint(Graphics g) {
		if (value.startsWith("Error")) {
			super.setValue(null);
			super.paint(g);
			g.drawImage(errorImage, 0, 2, null);
			int stringHeight = getFont().getSize();
			g.drawString(value, 20, getHeight() - ((getHeight() - stringHeight) / 2) - 2);
		} else {
			super.paint(g);
		}
	}
}
